package com.ruoyi.project.website;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.shiro.service.RegisterService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.business.domain.Business;
import com.ruoyi.project.system.business.service.IBusinessService;
import com.ruoyi.project.system.dept.domain.Dept;
import com.ruoyi.project.system.dept.service.IDeptService;
import com.ruoyi.project.system.joinus.domain.Joinus;
import com.ruoyi.project.system.joinus.service.IJoinusService;
import com.ruoyi.project.system.user.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping()
public class WebSiteController extends BaseController{

    @Autowired
    private IJoinusService joinusService;

    @Autowired
    private IBusinessService businessService;

    @Autowired
    private RegisterService registerService;

    @Autowired
    private IDeptService deptService;

    @GetMapping("index.html")
    public String index()
    {
        return "web/index";
    }

    @GetMapping("product.html")
    public String product()
    {
        return "web/product";
    }

    @GetMapping("version1.html")
    public String version1()
    {
        return "web/version1";
    }

    @GetMapping("version2.html")
    public String version2()
    {
        return "web/version2";
    }

    @GetMapping("service.html")
    public String service()
    {
        return "web/service";
    }

    @GetMapping("partner.html")
    public String partner()
    {
        return "web/partner";
    }

    @GetMapping("business.html")
    public String business()
    {
        return "web/business";
    }

    @GetMapping("company.html")
    public String company()
    {
        return "web/company";
    }

    @GetMapping("register.html")
    public String register()
    {
        return "web/register";
    }

    @PostMapping("/regsave.html")
    @ResponseBody
    public AjaxResult regsave(User user)
    {
        user.setLoginName(user.getUserName());
        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }

    @RequestMapping("/joinus.html")
    @ResponseBody
    public AjaxResult joinus(Joinus joinus)
    {
        return toAjax(joinusService.insert(joinus));
    }

    @RequestMapping("/business.html")
    @ResponseBody
    public AjaxResult business(Business business)
    {
        return toAjax(businessService.insertBusiness(business));
    }

    @RequestMapping("deptlist.html")
    @ResponseBody
    public AjaxResult deptlist()
    {
        List<Dept> deptList = deptService.selectallList();
        return AjaxResult.success(deptList);
    }

    @GetMapping("ulogin.html")
    public String ulogin()
    {
        return "web/login";
    }
}
